package com.qst.order.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.qst.order.domain.ReturnApplyItem;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

import java.math.BigDecimal;
import java.util.List;
@Mapper
public interface ReturnApplyItemMapper extends BaseMapper<ReturnApplyItem> {

    /**
     * 批量插入退货明细
     */
    @Insert("<script>" +
            "INSERT INTO return_apply_item (return_id, item_no, product_id, refund_quantity, reason) " +
            "VALUES " +
            "<foreach collection='list' item='item' separator=','>" +
            "(#{item.returnId}, #{item.itemNo}, #{item.productId}, #{item.refundQuantity}, #{item.reason})" +
            "</foreach>" +
            "</script>")
    void batchInsert(@Param("list") List<ReturnApplyItem> items);



    /**
     * 根据退货ID查询退货明细列表（关联商品信息）
     * @param returnId 退货申请ID
     * @return 退货明细列表
     */
    List<ReturnApplyItem> selectItemsByReturnId(Integer returnId);

    BigDecimal selectRefundAmount(Integer returnId);
}